package com.csii.mobilebanking.user;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
import com.csii.mobilebanking.R;
import com.csii.mobilebanking.tool.HpGlobals;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.telephony.SmsManager;
import android.telephony.gsm.SmsMessage;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.inputmethod.InputMethod;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {
	// 初始化时候 都是随机排序的
	private String[] digitals = { "1", "2", "3", "4", "5", "6", "7", "8", "9",
			"0" };
	private String[] phoneNums = { "1", "2", "3", "4", "5", "6", "7", "8", "",
			"9", "0", "删除" };
	List<String> numsList;
	private String[] specialChars = { "!", "@", "#", "$", "%", "^", "&", "*",
			"(", ")", ",", ".", "/", "?", ";", "\"" };
	private String[] digitalsAndSpecialChars = new String[digitals.length
			+ specialChars.length];// to-do
	private String[] otherSpecialChars = { "[", "]", "{", "}", "+", "<", ">",
			"|", "`", "~", "'", "\\", "-", "_", "。", "。", "。", "。", "。", "。",
			"。", "。", "。", "。", "。", "。" };
	private String[] characterLower = { "a", "b", "c", "d", "e", "f", "g", "h",
			"i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
			"v", "w", "x", "y", "z" };
	private String[] characterUpper = { "A", "B", "C", "D", "E", "F", "G", "H",
			"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
			"V", "W", "X", "Y", "Z" };
	private String[] realShowCharacter = new String[26];

	private int[] ids = { R.id.tv1, R.id.tv2, R.id.tv3, R.id.tv4, R.id.tv5,
			R.id.tv6, R.id.tv7, R.id.tv8, R.id.tv9, R.id.tv10, R.id.tv11,
			R.id.tv12, R.id.tv13, R.id.tv14, R.id.tv15, R.id.tv16, R.id.tv17,
			R.id.tv18, R.id.tv19, R.id.tv20, R.id.tv21, R.id.tv22, R.id.tv23,
			R.id.tv24, R.id.tv25, R.id.tv26 };

	private TextView[] tvsInput = new TextView[ids.length];// 可以输入的
	private TextView[] tvsOfFirstRow = new TextView[10];// 数字键 在第一行
	private TextView[] tvsOtherSpecialChars = new TextView[16];// 出去数字键的其他特殊字符

	private TextView del;// 删除一个字符
	private TextView upperShiftLower;// 字母大小写及数字界面则是显示更多字符
	private TextView digitalShiftCharacter;// 数字和英文字母切换
	private TextView space;// 空格
	private TextView conform;// 确认
	private LinearLayout line_content;
	private LinearLayout line_keyboard;
	private LinearLayout line_focus;
	private RelativeLayout main_content;
	private Animation alphaAnimation;
	private Animation keyboardAnimation;
	private EditText staffno_id;
	private EditText pwd;
	private Button btn_login;
	TextView tv_help;
	private ImageView imgChk;
	private boolean booRembered = false;
	SharedPre sharedPre;
	private String model = "MODEL_ENGLISH";// MODEL_ENGLISH 英文 "DIGITALS“ 数字
											// 英文有大小写
	private String MODEL_ENGLISH = "MODEL_ENGLISH";
	private String MODEL_DIGITALS = "MODEL_DIGITALS";
	private String type = "ENGLISH_Lower";// ENGLISH_Lower 默认小写字母 ENGLISH_UPPER:
											// 大写字母 DIGITALS:数字和常用字符 22:纯字符
	private String ENGLISH_LOWER = "ENGLISH_Lower";
	private String ENGLISH_UPPER = "ENGLISH_UPPER";
	private String TYPE_DIGITALS = "TYPE_DIGITALS";
	private String TYPE_SPECIALCHARS = "TYPE_SPECIALCHARS";

	String username;
	String password;
	String verfycode;
	private ImageView img_verifcodeView;
	private Button btn_sms;
	private EditText verificationcode;
	private static final int errTimes_Hour = 3;// 一小时内 输入最大可以输入次数
	private static final int errTimes_Day = 6;// 解除锁定后 输入最大可以输入次数
	private Date LockedDateTime;// 锁定开始时间
	private long waitTime = 60; // 锁定等待的时间 单位 s
	private int tryTimes = 0;// 登录失败次数累计
	private TextView line_login_type;
	private TextView tv_login_type;// 登录类型 用户名 -图片验证码 或 手机号-短信验证码

	private String[] array_type = new String[] { "用户名", "手机号" };
	private TimerCount timer;
	/* 自定义ACTION常数，作为广播的Intent Filter识别常数 */
	SMSReceiver smsReceiver;
	private GridView gridview;
	private GridAdapter mGridAdapter;
	private TextView img_back;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);// 全屏
		this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);// 当前activity禁用截屏

		this.setContentView(R.layout.login);
		sharedPre = new SharedPre(this);
		booRembered = sharedPre.GetLoginNameSave();
		// 数字和字符数组
		System.arraycopy(digitals, 0, digitalsAndSpecialChars, 0,
				digitals.length);
		System.arraycopy(specialChars, 0, digitalsAndSpecialChars,
				digitals.length, specialChars.length);
		initView();
		// 注册广播 发送消息
		smsReceiver = new SMSReceiver();
		registerReceiver(smsReceiver, new IntentFilter(
				GlobalConstant.SMS_SEND_ACTIOIN));
		regListenter();
		// 动画 user
		alphaAnimation = AnimationUtils.loadAnimation(this,
				R.drawable.push_right_in);
		alphaAnimation.setFillEnabled(true); // 启动Fill保持
		alphaAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面
		line_content.setAnimation(alphaAnimation);
	}

	private void resetDatas(String type, final EditText editText) {
		if (type.equals(ENGLISH_LOWER)) {
			permuteBySort(characterLower);
			realShowCharacter = characterLower;
		} else if (type.equals(ENGLISH_UPPER)) {
			permuteBySort(characterUpper);
			realShowCharacter = characterUpper;
		} else if (type.equals(TYPE_DIGITALS)) {
			permuteBySort(digitals);
			permuteBySort(specialChars);
		} else if (type.equals(TYPE_SPECIALCHARS)) {
			permuteBySort(otherSpecialChars);
			realShowCharacter = otherSpecialChars;
		}

		for (int i = 0; i < tvsInput.length; i++) {
			if (type.equals(TYPE_DIGITALS)) {
				if (i < 10) {
					tvsInput[i].setText(digitals[i]);
				} else {
					tvsInput[i].setText(specialChars[i - 10]);
				}
			} else {

				tvsInput[i].setText(realShowCharacter[i]);
			}
			final TextView item = tvsInput[i];
			item.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					String before = editText.getText().toString();
					String adding = item.getText().toString().trim();
					if (editText.getId() == R.id.verificationcode) {
						if (before.length() < 4) {
							editText.setText(before + adding);
							editText.setSelection((before + adding).length());
						}
					} else if (editText.getId() == R.id.staffno_id) {
						if (GlobalCache.LOGIN_TYPE == GlobalConstant.LOGIN_USERNAME) {
							if (before.length() < 14) {
								editText.setText(before + adding);
								editText.setSelection((before + adding)
										.length());
							}
						}
					} else if (editText.getId() == R.id.pwd) {
						editText.setText(before + adding);
						editText.setSelection((before + adding).length());
					}
				}
			});
		}

	}

	private void initView() {
		img_back = (TextView) findViewById(R.id.tv_home);
		main_content = (RelativeLayout) findViewById(R.id.main_content);
		line_login_type = (TextView) findViewById(R.id.tv_login_type);
		tv_login_type = (TextView) findViewById(R.id.tv_login_type);
		img_verifcodeView = (ImageView) findViewById(R.id.img_verifcodeView);
		img_verifcodeView.setImageBitmap(BPUtil.getInstance().createBitmap());
		verfycode = BPUtil.getInstance().getCode();
		btn_sms = (Button) findViewById(R.id.btn_sms);
		line_content = (LinearLayout) findViewById(R.id.line_content);
		line_keyboard = (LinearLayout) findViewById(R.id.line_keyboard);
		gridview = (GridView) findViewById(R.id.gridview);
		line_focus = (LinearLayout) findViewById(R.id.line_focus);
		btn_login = (Button) findViewById(R.id.login);
		tv_help = (TextView) findViewById(R.id.tv_help);
		imgChk = (ImageView) findViewById(R.id.check);
		if (booRembered) {
			imgChk.setBackgroundDrawable(getResources().getDrawable(
					R.drawable.login_checkbox_btn_pressed));
		} else if (!booRembered) {
			imgChk.setBackgroundDrawable(getResources().getDrawable(
					R.drawable.login_checkbox_btn));
		}
		staffno_id = (EditText) findViewById(R.id.staffno_id);
		staffno_id.setText(sharedPre.getLoginName());
		pwd = (EditText) findViewById(R.id.pwd);
		staffno_id.setInputType(InputType.TYPE_NULL);// 永远都不弹出输入法
		// staffno_id.setFilters(new InputFilter[] { new
		// InputFilter.LengthFilter(
		// 16) });
		pwd.setInputType(InputType.TYPE_NULL);
		verificationcode = (EditText) findViewById(R.id.verificationcode);
		verificationcode.setInputType(InputType.TYPE_NULL);// xml 里面定义无效？
		// verificationcode
		// .setFilters(new InputFilter[] { new InputFilter.LengthFilter(4) });
		// 数据随机排序

		// 键盘
		for (int i = 0; i < ids.length; i++) {
			TextView tvItem = (TextView) findViewById(ids[i]);
			tvsInput[i] = tvItem;
		}

		// tvsOfFirstRow 初始化
		System.arraycopy(tvsInput, 0, tvsOfFirstRow, 0, 10);
		// 赋值

		//
		System.arraycopy(tvsInput, 10, tvsOtherSpecialChars, 0, 10);
		System.arraycopy(tvsInput, 20, tvsOtherSpecialChars, 10, 6);//

		del = (TextView) findViewById(R.id.del);
		conform = (TextView) findViewById(R.id.conform);
		space = (TextView) findViewById(R.id.space);
		space.setText("空格");
		upperShiftLower = (TextView) findViewById(R.id.upperShiftLower);
		upperShiftLower.setText("abc");// 默认小写字母
		digitalShiftCharacter = (TextView) findViewById(R.id.digitalShiftCharacter);
		digitalShiftCharacter.setText("123");// 默认数字
	}

	private void permuteBySort(String[] characterLower) {
		Date dt = new Date();
		Random random = new Random(dt.getSeconds());
		int len = characterLower.length;
		for (int i = 0; i < len; i++) {
			int pos = (int) (random.nextDouble() * (len - i + 1) + i) - 1;
			String temp = characterLower[i];
			characterLower[i] = characterLower[pos];
			characterLower[pos] = temp;
		}
	}

	private void regListenter() {
		tv_help.setOnClickListener(this);
		img_back.setOnClickListener(this);
		line_login_type.setOnClickListener(this);
		btn_login.setOnClickListener(this);
		imgChk.setOnClickListener(this);
		btn_sms.setOnClickListener(this);
		img_verifcodeView.setOnClickListener(this);
		del.setOnClickListener(this);
		conform.setOnClickListener(this);
		space.setOnClickListener(this);
		upperShiftLower.setOnClickListener(this);
		digitalShiftCharacter.setOnClickListener(this);
		tv_login_type.addTextChangedListener(new TextWatcher() {

			@Override
			public void onTextChanged(CharSequence s, int start, int before,
					int count) {
				// TODO Auto-generated method stub

			}

			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {
				// TODO Auto-generated method stub

			}

			@Override
			public void afterTextChanged(Editable s) {
				clearEdit();
				hideKeyboards();// 为什么没效果
				if (GlobalCache.LOGIN_TYPE == GlobalConstant.LOGIN_USERNAME) {
					img_verifcodeView.setVisibility(View.VISIBLE);
					btn_sms.setVisibility(View.GONE);
				} else if (GlobalCache.LOGIN_TYPE == GlobalConstant.LOGIN_PHONENUMBER) {
					img_verifcodeView.setVisibility(View.GONE);
					btn_sms.setVisibility(View.VISIBLE);
				}
			}
		});
		gridview.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				if (arg2 == 11) {
					// 删除
					delOneChar();
				} else if (arg2 == 8) {
					// 空白
				} else {
					addPhoneNum(numsList.get(arg2));
				}
			}
		});

		staffno_id.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {

				if (hasFocus) {
					verificationcode.clearFocus();
					pwd.clearFocus();
					hideKeyboards();
					if (GlobalCache.LOGIN_TYPE == GlobalConstant.LOGIN_USERNAME) {
						getKeyBoard();
						resetDatas(type, staffno_id);
					} else if (GlobalCache.LOGIN_TYPE == GlobalConstant.LOGIN_PHONENUMBER) {
						showPhoneKey();
					}
				} else if (!hasFocus) {
					hideKeyboards();
				}
			}
		});

		pwd.setTransformationMethod(PasswordTransformationMethod.getInstance()); // 否则隐藏密码
		pwd.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					verificationcode.clearFocus();
					staffno_id.clearFocus();
					if (!line_keyboard.isShown()) {
						getKeyBoard();
						resetDatas(type, pwd);
					}

				} else if (!hasFocus) {
					hideKeyboards();
				}
			}
		});
		verificationcode.setOnFocusChangeListener(new OnFocusChangeListener() {

			@Override
			public void onFocusChange(View v, boolean hasFocus) {
				if (hasFocus) {
					pwd.clearFocus();
					staffno_id.clearFocus();
					if (!line_keyboard.isShown()) {
						getKeyBoard();
						resetDatas(type, verificationcode);
					}
				} else if (!hasFocus) {
					hideKeyboards();
				}

			}
		});
	}

	protected void showPhoneKey() {
		numsList = new ArrayList<String>();
		for (String item : phoneNums) {
			numsList.add(item);
		}
		mGridAdapter = new GridAdapter(LoginActivity.this, numsList);
		gridview.setAdapter(mGridAdapter);
		gridview.setVisibility(View.VISIBLE);
		gridview.invalidate();
	}

	// 清空edittext焦点和数据
	protected void clearEdit() {
		staffno_id.setText("");
		pwd.setText("");
		verificationcode.setText("");
		staffno_id.clearFocus();
		pwd.clearFocus();
		verificationcode.clearFocus();
		line_focus.requestFocus();
		line_focus.setFocusable(true);
		line_focus.setFocusableInTouchMode(true);
	}

	protected void hideKeyboard() {
		line_keyboard.setVisibility(View.GONE);

	}

	protected void hidePhoneKeyboard() {
		gridview.setVisibility(View.GONE);

	}

	protected void hideKeyboards() {

		line_keyboard.setVisibility(View.GONE);
		gridview.setVisibility(View.GONE);
	}

	protected void getKeyBoard() {
		line_keyboard.setVisibility(View.VISIBLE);
		// keyboardAnimation = AnimationUtils.loadAnimation(MainActivity.this,
		// R.drawable.push_right_in);
		// keyboardAnimation.setFillEnabled(true); // 启动Fill保持
		// keyboardAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面 保留在终止的位置
		// line_keyboard.setAnimation(keyboardAnimation);
		line_keyboard.invalidate();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.login:
			// 模拟用户信息
			XGUserAccount mAccount = new XGUserAccount();
			mAccount.RealName = "吕建中";
			mAccount.UserID = "f327888576";
			HpGlobals.mXGUserAccount = mAccount;
			GlobalJumpAc.goFragmentAc(this);
			// verfyUserInfos();

			break;
		case R.id.tv_help:
			GlobalJumpAc.goHelpAc(this);
			// verfyUserInfos();

			break;
		case R.id.tv_home:
			GlobalJumpAc.goFirstAc(this);
			break;
		case R.id.tv_login_type:

			new LoginPopuWindow(LoginActivity.this, line_login_type,
					tv_login_type);

			break;
		case R.id.img_verifcodeView:
			img_verifcodeView.setImageBitmap(BPUtil.getInstance()
					.createBitmap());
			verfycode = BPUtil.getInstance().getCode();
			img_verifcodeView.invalidate();
			break;
		case R.id.btn_sms:

			getMSMCode();
			break;

		case R.id.check:
			sharedPre = new SharedPre(this);
			booRembered = sharedPre.GetLoginNameSave();
			if (booRembered) {
				imgChk.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.login_checkbox_btn));
				sharedPre.SetLoginNameSave(false);
			} else if (!booRembered) {
				imgChk.setBackgroundDrawable(getResources().getDrawable(
						R.drawable.login_checkbox_btn_pressed));
				sharedPre.SetLoginNameSave(true);
			}
			break;

		case R.id.del:
			delOneChar();
			break;
		case R.id.conform:
			hideKeyboardWAnim();

			break;
		case R.id.space:
			addSpace();
			break;
		case R.id.upperShiftLower:
			if (model.equals(MODEL_ENGLISH)) {
				if (type.equals(ENGLISH_LOWER)) {
					type = ENGLISH_UPPER;
					upperShiftLower.setText("ABC");
				} else if (type.equals(ENGLISH_UPPER)) {
					type = ENGLISH_LOWER;
					upperShiftLower.setText("abc");
				}

			} else if (model.equals(MODEL_DIGITALS)) {
				if (type.equals(TYPE_DIGITALS)) {
					type = TYPE_SPECIALCHARS;
					upperShiftLower.setText("123");
				} else if (type.equals(TYPE_SPECIALCHARS)) {
					type = TYPE_DIGITALS;
					upperShiftLower.setText("#+=");
				}
			}
			// 判断那个editetext
			if (staffno_id.isFocused()) {
				resetDatas(type, staffno_id);
			} else if (pwd.isFocused()) {
				resetDatas(type, pwd);
			} else if (verificationcode.isFocused()) {
				resetDatas(type, verificationcode);
			}

			break;

		case R.id.digitalShiftCharacter:
			if (model.equals(MODEL_ENGLISH)) {
				type = TYPE_DIGITALS;
				upperShiftLower.setText("#+=");
				digitalShiftCharacter.setText("abc");
				model = MODEL_DIGITALS;
			} else if (model.equals(MODEL_DIGITALS)) {
				if (type.equals(TYPE_DIGITALS)) {
					type = ENGLISH_LOWER;
					model = MODEL_ENGLISH;
					upperShiftLower.setText("abc");
					digitalShiftCharacter.setText("123");
				} else if (type.equals(TYPE_SPECIALCHARS)) {
					type = ENGLISH_LOWER;
					model = MODEL_ENGLISH;
					upperShiftLower.setText("123");
					digitalShiftCharacter.setText("abc");
				}

			}
			// 判断那个editetext
			if (staffno_id.isFocused()) {
				resetDatas(type, staffno_id);
			} else if (pwd.isFocused()) {
				resetDatas(type, pwd);
			} else if (verificationcode.isFocused()) {
				resetDatas(type, verificationcode);
			}
			break;
		default:
			break;
		}

	}

	private void getMSMCode() {
		// 获取发送地址和发送内容
		String messageNumber = staffno_id.getText().toString();
		// 只能以1开头 并且11位
		if (messageNumber.length() == 11) {

			SmsMng mSmsMng = new SmsMng(LoginActivity.this);
			mSmsMng.sendSms(messageNumber);
			timer = new TimerCount(1000 * 30, 1000);
			timer.start();// 开始计时
		} else {
			Toast.makeText(this, "手机号码输入错误", Toast.LENGTH_SHORT).show();
		}

	}

	class SMSReceiver extends BroadcastReceiver {

		@Override
		public void onReceive(Context context, Intent intent) {
			if (intent.getAction().equals(GlobalConstant.SMS_SEND_ACTIOIN)) {
				switch (getResultCode()) {

				case Activity.RESULT_OK:
					/* 发送短信成功 */

					break;
				case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
					/* 发送短信失败 */

					break;
				case SmsManager.RESULT_ERROR_NO_SERVICE:
					/* 发送短信成功 */

					break;
				default:
					break;
				}
			}

		}

	}

	/* 定义一个倒计时的内部类 */
	class TimerCount extends CountDownTimer {

		public TimerCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
		}

		@Override
		public void onFinish() {
			// 计时完毕时触发
			btn_sms.setText("重新验证");
			btn_sms.setClickable(true);

		}

		@Override
		public void onTick(long millisUntilFinished) {
			// 计时过程显示
			btn_sms.setClickable(false);
			btn_sms.setText(millisUntilFinished / 1000 + "秒");

		}

	}

	private void verfyUserInfos() {

		boolean chked = chk();
		if (chked) {
			GlobalJumpAc.goExpListAc(this);
			if (booRembered) {
				sharedPre.SetLoginNameSave(false);
				sharedPre.SetLoginName("");
			} else if (!booRembered) {
				sharedPre.SetLoginNameSave(true);
				sharedPre.SetLoginName(staffno_id.getText().toString());
			}
		} else {
			tryTimes++;
		}

	}

	private boolean chk() {
		boolean chked = false;
		String uname = staffno_id.getText().toString();
		String upwd = pwd.getText().toString();
		String uverfycode = verificationcode.getText().toString();

		if (tryTimes == 3) {
			// todo 三次 禁用 比如1小时 现在时间和服务器时间的间隔

		} else if (uname.length() == 0) {
			// 提示

		} else if (upwd.length() == 0) {
			// 提示
		} else if (uverfycode.equals(verfycode)) {
			// to do
		} else if (username.equals(uname) || password.equals(upwd)) {
			// todo
		} else if (username.equals(uname) && password.equals(upwd)) {

			// 用户单点登录控制--服务端返回是否有在线标记

			// 登录成功后销毁原有Session，新建纯净Session保存用户及交易数据
			chked = true;
		}
		return chked;
	}

	private void hideKeyboardWAnim() {

		keyboardAnimation = AnimationUtils.loadAnimation(LoginActivity.this,
				R.anim.slide_down_out);
		// keyboardAnimation.setFillEnabled(true); // 启动Fill保持
		// keyboardAnimation.setFillAfter(true); // 设置动画的最后一帧是保持在View上面
		line_keyboard.setAnimation(keyboardAnimation);
		line_keyboard.setVisibility(View.GONE);
	}

	private void addSpace() {
		if (staffno_id.isFocused()) {
			String before = staffno_id.getText().toString().trim();
			staffno_id.setText(before + " ");
			staffno_id.setSelection(before.length() + 1);
		} else if (pwd.isFocused()) {
			String before = pwd.getText().toString().trim();
			pwd.setText(before + " ");
			pwd.setSelection(before.length() + 1);
		} else if (verificationcode.isFocused()) {
			String before = verificationcode.getText().toString().trim();
			verificationcode.setText(before + " ");
			verificationcode.setSelection(before.length() + 1);
		}

	}

	// 点击一下 删除一个字符
	private void delOneChar() {
		if (staffno_id.isFocused()) {
			String before = staffno_id.getText().toString();
			if (before.length() > 0) {
				String nowStr = before.substring(0, before.length() - 1);
				staffno_id.setText(nowStr);
				staffno_id.setSelection(nowStr.length());
			}
		} else if (pwd.isFocused()) {
			String before = pwd.getText().toString();
			if (before.length() > 0) {
				String nowStr = before.substring(0, before.length() - 1);
				pwd.setText(nowStr);
				pwd.setSelection(nowStr.length());
			}
		} else if (verificationcode.isFocused()) {
			String before = verificationcode.getText().toString();
			if (before.length() > 0) {
				String nowStr = before.substring(0, before.length() - 1);
				verificationcode.setText(nowStr);
				verificationcode.setSelection(nowStr.length());
			}
		}

	}

	private void addPhoneNum(String ch) {
		if (staffno_id.isFocused()) {
			String before = staffno_id.getText().toString().trim();
			if (before.length() < 11) {
				staffno_id.setText(before + ch);
				staffno_id.setSelection(before.length() + 1);
			}
		}
	}

	// popu window
	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		/* 取消注册自定义Receiver */
		unregisterReceiver(smsReceiver);

		if (booRembered) {
			sharedPre.SetLoginNameSave(false);
			sharedPre.SetLoginName("");
		} else if (!booRembered) {
			sharedPre.SetLoginNameSave(true);
			sharedPre.SetLoginName(staffno_id.getText().toString());
		}
		this.finish();
	}

}
